package com.yr.ryjk.backdoor;

import java.util.Map;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yr.ryjk.backdoor.entity.Backdoor;
import com.yr.ryjk.backdoor.service.IBackdoorService;
import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.interceptor.authority.For;
import com.yr.ryjk.interceptor.authority.UserType;
import com.yr.ryjk.util.JSONUtil;

/**
 * 
 * @author hxjxiaojun
 */
@For(user=UserType.WEBSERVER_USER)
@Controller
@RequestMapping("/backdoor")
public class BackdoorController {
	@Autowired
	private IBackdoorService backdoorService;
	
	/**
	 * app端获取后门
	 * @return
	 */
	@For(user=UserType.APP_USER)
	@RequestMapping(value = "/getBackdoor", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getBackdoor() {
		return JSONUtil.getJSON(ErrorType.SUCCESS,backdoorService.getBackdoor());
	}
	
	/**
	 * 后台获取后门信息
	 * @param id 
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> list(String id) {
		return JSONUtil.getJSON(ErrorType.SUCCESS,backdoorService.selectByPrimaryKey(id));
	}
	
	/**
	 * 后台添加后门信息
	 * @param backdoor
	 * @return
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(Backdoor backdoor) {
		backdoorService.add(backdoor);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
	
	
	/**
	 * 修改后门信息
	 * @param id
	 * @param status
	 * @param name
	 * @param url
	 * @return
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modify(Backdoor backdoor) {
		backdoorService.modify(backdoor);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
	
	/**
	 * 删除后门信息
	 * @param id  
	 * @return
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> delete(@RequestParam("id") @NotBlank String id) {
		backdoorService.delete(id);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
}